package com.cenxi.common.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author cenxi
 * @Date 2023/8/16 14:39
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Resp<T> {
    static final String RES_MSG = "成功";
    static final String RES_CODE = "0000";
    @Builder.Default
    private String msg = RES_MSG;
    @Builder.Default
    private String code = RES_CODE;
    private T data;

    public static <T> Resp<T> error() {
        return Resp.<T>builder()
                .msg("网络波动").code("0001")
                .build();
    }

    public static <T> Resp<T> error(String msg, String code) {
        return Resp.<T>builder()
                .msg(msg).code(code)
                .build();
    }

    public static <T> Resp<T> error(String msg) {
        return Resp.<T>builder()
                .msg(msg).code("0001")
                .build();
    }

    public static <T> Resp<T> error(T data) {
        return Resp.<T>builder()
                .msg("网络波动").code("0001").data(data)
                .build();
    }

    public static <T> Resp<T> succeed() {
        return Resp.<T>builder()
                .build();
    }

    public static <T> Resp<T> succeed(T data) {
        return Resp.<T>builder()
                .data(data)
                .build();
    }

    public static <T> Resp<T> succeed(String msg, T data) {
        return Resp.<T>builder()
                .msg(msg).data(data)
                .build();
    }
}
